/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.server.search.controller;

import offset.nodes.server.controller.Attribute;
import offset.nodes.server.view.list.ColumnInfo;
import offset.nodes.server.view.list.PageableList;
import offset.nodes.server.view.list.SortingInfo;
import offset.nodes.server.model.RepositoryUtils;
import offset.nodes.server.search.model.SearchModel;
import offset.nodes.server.search.model.SearchType;

/**
 * This is the memory of a given query and its result list. All attributes are stored here, that must be persisted across multiple requests.
 * 
 * @author Walter Lütgenau
 */
public class QueryAttribute extends Attribute {
    SearchModel model;
    String query = null;
    SearchType queryType = SearchType.text;
    PageableList result = null;
    SortingInfo sortingInfo = null;
    ColumnInfo columnInfo = null;
    
    public static final String ATT_QUERY = "query";

    public QueryAttribute() {
        super(ATT_QUERY);
        this.model = RepositoryUtils.getSearchModel();
    }
    
    public QueryAttribute(SearchModel model, String query, SearchType queryType) {
        super(ATT_QUERY);
        this.model = model;
        this.query = query;
        this.queryType = queryType;
        this.result = null;
    }
    
    public boolean isEmpty() {
        return query == null || query.length() == 0;
    }

    public SearchModel getModel() {
        return model;
    }

    public void setModel(SearchModel model) {
        this.model = model;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public SearchType getQueryType() {
        return queryType;
    }

    public void setQueryType(SearchType queryType) {
        this.queryType = queryType;
    }

    public PageableList getResult() {
        return result;
    }

    public void setResult(PageableList result) {
        this.result = result;
    }

    public SortingInfo getSortingInfo() {
        return sortingInfo;
    }

    public void setSortingInfo(SortingInfo sortingInfo) {
        this.sortingInfo = sortingInfo;
    }

    public ColumnInfo getColumnInfo() {
        return columnInfo;
    }

    public void setColumnInfo(ColumnInfo columnInfo) {
        this.columnInfo = columnInfo;
    }
}
